package cn.itcast.web.action;

import cn.itcast.domain.system.Permission;
import cn.itcast.service.PermissionService;
import cn.itcast.web.action.common.BaseAction;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import java.util.List;

@Namespace("/")
@ParentPackage("json-default")
@Controller
@Scope("prototype")
@Actions
public class PermissionAction extends BaseAction<Permission> {
    @Autowired
    private PermissionService permissionService;
    //url:../../permission_list.action
    @Action(value = "permission_list",results = {@Result(name = "success",type = "json")})
    public String findAll(){
        List<Permission> permissions= permissionService.findAll();
        ServletActionContext.getContext().getValueStack().push(permissions);
        return SUCCESS;
    }
//    action="../../permission_save.action">
    @Action(value = "permission_save",results = {
            @Result(name = "success",location = "pages/system/permission.html",type = "redirect")})
    public String save(){
      permissionService.save(model);
        return SUCCESS;
    }
}
